home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Graphics Programming (2nd Edition) / Visual Basic Graphics Programming 2nd Edition.iso / OldSrc / CH3 / SRC / SYSMAP.FRM < prev    next >
Text File  |  1996-05-02  |  5KB  |  193 lines

  1. VERSION 4.00
  2. Begin VB.Form SysMapForm 
  3.    Caption         =   "SysMap"
  4.    ClientHeight    =   3495
  5.    ClientLeft      =   1500
  6.    ClientTop       =   1260
  7.    ClientWidth     =   6270
  8.    Height          =   4185
  9.    Left            =   1440
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   3495
  12.    ScaleWidth      =   6270
  13.    Top             =   630
  14.    Width           =   6390
  15.    Begin VB.TextBox EntryText 
  16.       BeginProperty Font 
  17.          name            =   "Courier New"
  18.          charset         =   1
  19.          weight          =   400
  20.          size            =   8.25
  21.          underline       =   0   'False
  22.          italic          =   0   'False
  23.          strikethrough   =   0   'False
  24.       EndProperty
  25.       Height          =   3495
  26.       Left            =   3480
  27.       MultiLine       =   -1  'True
  28.       ScrollBars      =   2  'Vertical
  29.       TabIndex        =   1
  30.       Text            =   "SYSMAP.frx":0000
  31.       Top             =   0
  32.       Width           =   2775
  33.    End
  34.    Begin VB.PictureBox Pict 
  35.       AutoRedraw      =   -1  'True
  36.       Height          =   3495
  37.       Left            =   0
  38.       ScaleHeight     =   229
  39.       ScaleMode       =   3  'Pixel
  40.       ScaleWidth      =   221
  41.       TabIndex        =   0
  42.       Top             =   0
  43.       Width           =   3375
  44.    End
  45.    Begin MSComDlg.CommonDialog FileDialog 
  46.       Left            =   3240
  47.       Top             =   3120
  48.       _version        =   65536
  49.       _extentx        =   847
  50.       _extenty        =   847
  51.       _stockprops     =   0
  52.       cancelerror     =   -1  'True
  53.    End
  54.    Begin VB.Menu mnuFile 
  55.       Caption         =   "&File"
  56.       Begin VB.Menu mnuFileLoad 
  57.          Caption         =   "&Load..."
  58.          Shortcut        =   ^L
  59.       End
  60.       Begin VB.Menu mnuFileSep 
  61.          Caption         =   "-"
  62.       End
  63.       Begin VB.Menu mnuFileExit 
  64.          Caption         =   "E&xit"
  65.       End
  66.    End
  67. End
  68. Attribute VB_Name = "SysMapForm"
  69. Attribute VB_Creatable = False
  70. Attribute VB_Exposed = False
  71. Option Explicit
  72.  
  73. ' ***********************************************
  74. ' Display a list of the colors in the logical
  75. ' palette and how they map to the system palette.
  76. ' ***********************************************
  77. Sub ShowEntries()
  78. Dim num_entries As Integer
  79. Dim palentry(0 To 255) As PALETTEENTRY
  80. Dim pixel As Byte
  81. Dim num As Long
  82. Dim orig_color As Long
  83. Dim i As Integer
  84. Dim txt As String
  85. Dim istr As String
  86. Dim pixelstr As String
  87. Dim rstr As String
  88. Dim gstr As String
  89. Dim bstr As String
  90.  
  91.     If Pict.Picture = 0 Then
  92.         EntryText.Text = "No picture loaded."
  93.         Exit Sub
  94.     ElseIf Pict.Picture.hPal = 0 Then
  95.         EntryText.Text = "Default palette."
  96.         Exit Sub
  97.     End If
  98.     
  99.     num_entries = GetPaletteEntries(Pict.Picture.hPal, 0, 256, palentry(0))
  100.     
  101.     ' Save the color of pixel (0, 0).
  102.     orig_color = Pict.Point(0, 0)
  103.  
  104.     txt = "Log Sys  Red Green Blue" & vbCrLf
  105.     For i = 0 To num_entries - 1
  106.         ' See to what system entry each logical
  107.         ' palette entry is mapped.
  108.         Pict.PSet (0, 0), i + &H1000000
  109.         
  110.         num = GetBitmapBits(Pict.Image, 1, pixel)
  111.         
  112.         ' Add the information to the string.
  113.         istr = Format$(i)
  114.         pixelstr = Format$(pixel)
  115.         rstr = Format$(palentry(i).peRed)
  116.         gstr = Format$(palentry(i).peGreen)
  117.         bstr = Format$(palentry(i).peBlue)
  118.         txt = txt & _
  119.             Space$(3 - Len(istr)) & istr & _
  120.             Space$(4 - Len(pixelstr)) & pixelstr & _
  121.             Space$(5 - Len(rstr)) & rstr & _
  122.             Space$(6 - Len(gstr)) & gstr & _
  123.             Space$(5 - Len(bstr)) & bstr & vbCrLf
  124.     Next i
  125.  
  126.     ' Restore pixel (0, 0) to its original color.
  127.     Pict.PSet (0, 0), orig_color
  128.     
  129.     EntryText.Text = txt
  130. End Sub
  131.  
  132. Private Sub Form_Load()
  133.     ' Make sure the screen supports palettes.
  134.     If Not GetDeviceCaps(hDC, RASTERCAPS) And RC_PALETTE Then
  135.         Beep
  136.         MsgBox "This monitor does not support palettes.", _
  137.             vbCritical
  138.         End
  139.     End If
  140.  
  141.     ShowEntries
  142. End Sub
  143.  
  144.  
  145.  
  146. Private Sub Form_Resize()
  147. Dim wid As Single
  148.  
  149.     EntryText.Move ScaleWidth - EntryText.Width, _
  150.         0, EntryText.Width, ScaleHeight
  151.     
  152.     wid = EntryText.Left - 20
  153.     If wid < 100 Then wid = 100
  154.     Pict.Move 0, 0, wid, ScaleHeight
  155. End Sub
  156.  
  157. Private Sub Form_Unload(Cancel As Integer)
  158.     End
  159. End Sub
  160.  
  161. Private Sub mnuFileExit_Click()
  162.     Unload Me
  163. End Sub
  164.  
  165. Private Sub mnuFileLoad_Click()
  166. Dim fname As String
  167.  
  168.     ' Allow the user to pick a file.
  169.     On Error Resume Next
  170.     FileDialog.filename = "*.BMP;*.ICO;*.RLE;*.WMF;*.DIB"
  171.     FileDialog.Flags = cdlOFNFileMustExist + cdlOFNHideReadOnly
  172.     FileDialog.ShowOpen
  173.     If Err.Number = cdlCancel Then
  174.         Exit Sub
  175.     ElseIf Err.Number <> 0 Then
  176.         Beep
  177.         MsgBox "Error selecting file.", , vbExclamation
  178.         Exit Sub
  179.     End If
  180.     On Error GoTo 0
  181.     
  182.     fname = Trim$(FileDialog.filename)
  183.     FileDialog.InitDir = Left$(fname, Len(fname) _
  184.         - Len(FileDialog.FileTitle) - 1)
  185.  
  186.     ' Load the picture.
  187.     Pict.Picture = LoadPicture(fname)
  188.  
  189.     ' Update the list of colors.
  190.     ShowEntries
  191. End Sub
  192.  
  193.